/*
 * @Author: 肖芬芳 1911683843@qq.com
 * @Date: 2022-09-23 16:18:32
 * @LastEditors: 肖芬芳 1911683843@qq.com
 * @LastEditTime: 2022-12-09 15:34:08
 * @FilePath: \node_study\routes\admin\system\user\list.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const { json } = require('express');
const { object } = require('joi');
const {
    User
} = require('../../../model/user.js');

module.exports = async (req, res) => {
    // 获取post参数
    console.log(req.fields);
    let { pageSize, currentPage, data } = req.fields
    let users = await User.find({
        $and: [{ 'username': new RegExp(data.username) }
            // , { 'role': user.role == undefined ? new RegExp() : data.role }
            // , { 'phone': new RegExp(data.phone) }
            // , { 'status': data.status == undefined ? { $in: [1, 0] } : data.status }
        ]
    }).select("-password").sort('-createTime').skip((currentPage - 1) * pageSize).limit(pageSize)

    let totalCount = users.length;
    res.send({
        'code': 0,
        "totalCount": totalCount,
        "data": users
    });
}